<?php
namespace app\demo_record\model;

class ConfigFileModel
{
    /**
     * @var string $path 配置文件所在路径
     */
    protected $path;
    /**
     * 创建对象
     * @return self
     */
    static public function alloc($path="")
    {
        if(empty($path)) $path = CMF_ROOT . 'data/data_magic/config.json';
        $new = new static;
        $new->path=$path;
        return $new;
    }
    public function load()
    {
        $data=file_get_contents($this->path);
        $config=json_decode($data,true);
        return $config;
    }
    public function save($config)
    {
        $data=json_encode($config,JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
        return file_put_contents($this->path,$data);
    }
}
